|
|
|
|
|
|
|
For each surface, these algorithms determine which pixels make up that surface. They then color the surface appropriately. Programs that use a shading model or smooth shading use the scene's geometry to determine the colors of the pixels. |
|
|
|
|
|
|
|
|
Ray tracing approaches the problem from the opposite point of view. Instead of determining which pixels make up each object in the scene, a ray-tracing algorithm determines for each pixel in the screen what that pixel's color should be. |
|
|
|
|
|
|
|
|
The idea behind ray tracing is simple. For each pixel on the screen, the program passes a ray from the center of projection through the pixel. It follows the ray into the scene until it strikes an object. It then uses the geometry of that object, the direction of the ray, and the position of the light sources to determine the pixel's color. This basic process is illustrated in Figure 17.4. |
|
|
|
|
|
|
|
|
Because the algorithm follows each ray only until it reaches the closest surface, this method provides hidden surface removal. Any surface that lies behind another is ignored because the rays passing from the center of projection to the hidden object are blocked by the closer object, as shown in Figure 17.5. |
|
|
|
|
|
|
|
|
Ray tracing even handles mutually overlapping objects and situations like the one shown in Figure 17.6 where one object pierces another. These are difficult special cases that are not handled by the Depth-Sort hidden surface removal algorithm. |
|
|
|
|
|
|
|
|
To calculate a pixel's color, the ray-tracing algorithm can use any of the shading models described in Chapter 16, Shading Models. If you use the most complete model, your picture gets the benefits of ambient light, diffuse and specular reflection, and intensity reduction due to distance. |
|
|
|
|
|
|
|
|
With only a small change, you can make the algorithm display shadows as well. Before you calculate the diffuse and specular reflection components of a pixel's color, you should check to see if there is any object between the pixel and each light source. You can do this |
|
|
|
|
|
|
|
|
Figure 17.4
Ray tracing follows a ray from the center of projection,
through a pixel on the screen, until it reaches an object. |
|
|
|
|
|